<?php

// +----------------------------------------------------------------------
// | 行为事件
// +----------------------------------------------------------------------
// | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
// +----------------------------------------------------------------------
// | Author: 微尘 <yicmf@qq.com>
// +----------------------------------------------------------------------

namespace app\event\ucenter;

use app\common\event\Base;
use app\event\ucenter\User as UserEvent;
use app\model\ucenter\MemberInfo as MemberInfoModel;
use app\model\ucenter\User as UserModel;
use think\facade\Db;

class MemberInfo extends Base
{

    /**
     * 获取同级情况
     * @param $user
     * @param $bUser
     * @return float
     */
    public static function getSame($user, $bUser)
    {
        if (($user['level'] == 1 && $bUser['level'] == 1)
            || ($user['level'] == 2 && $bUser['level'] == 2)) {
            // 平级
            return 0.03;
        }
        return 0;
    }

    /**
     * 获取级差
     * @param $user
     * @param $bUser
     * @return float
     */
    public static function getDifferential($user, $bUser)
    {
        if (($user['level'] == 1 && $bUser['level'] == 2)
            || ($user['level'] == 2 && $bUser['level'] == 3)
            || ($user['level'] == 1 && $bUser['level'] == 3)
        ) {
            $bUserLevel = MemberInfoModel::where('type', 'in', [1, $bUser['level']])->order('type DESC')->where('id', '<', 5)->find();
            $userLevel = MemberInfoModel::where('type', 'in', [1, $user['level']])->order('type DESC')->where('id', '<', 5)->find();
            return ($bUserLevel['fee'] - $userLevel['fee']) > 0 ? ($bUserLevel['fee'] - $userLevel['fee']) : 0;
        }
        return 0;
    }

    /**
     * 获取上级老板  // 培养
     * @param $user
     * @param $bUser
     * @return float
     */
    public static function getBossToBoss($user, $bUser)
    {
        if ($bUser['level'] == 3 && $user['level'] == 3) {
            return 0.03;
        }
        return 0;
    }

    /**
     * 直接老板,自己不是，给间接培养
     * @param $user
     * @param $bUser
     * @return float
     */
    public static function getBossIndirect($user, $bUser, $bbUser)
    {

        if ($bUser['level'] == 3 && $user['level'] < 3 && $bbUser['level'] == 3) {
            //直接老板,自己不是，给间接培养
            return 0.03;
        }
        return false;
    }

    /**
     * 间接奖，必须是老板等级
     * @param $user
     * @param $bUser
     * @return float
     */
    public static function getBossIndirectBoss($user, $bUser, $bbUser)
    {

        if ($user['level'] < 3 && $bbUser['level'] == 3) {
            return 0.03;
        }
        return false;
    }
}
